package zfind

// 类型
const (
	FILETYPE_FILE = iota
	FILETYPE_DIR
)

type WalkCallBack func(xname string, xtype int, xattr interface{}) (goon bool, err error)

type FileWalker interface {
	Walk(xpath string, cb WalkCallBack) error
}

func ListType(fw FileWalker, path string, _type int) ([]string, error) {
	files := make([]string, 0, 40)
	fw.Walk(path, func(xname string, xtype int, xattr interface{}) (goon bool, err error) {
		if xtype == _type {
			files = append(files, xname)
		}
		return true, nil
	})

	return files, nil
}

func ListFiles(fw FileWalker, path string) ([]string, error) {
	return ListType(fw, path, FILETYPE_FILE)
}

func ListDirs(fw FileWalker, path string) ([]string, error) {
	return ListType(fw, path, FILETYPE_DIR)
}
